package com.jingtai.platform.service.supply.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jingtai.common.enums.DeleteFlagEnum;
import com.jingtai.common.template.ResultMapInfo;
import com.jingtai.core.entity.supply.UndertakesDetail;
import com.jingtai.core.mapper.supply.UndertakesDetailMapper;
import com.jingtai.platform.service.supply.UndertakesDetailService;
import com.jingtai.platform.util.ResultUtil;
import com.jingtai.platform.util.UrlToMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
 * 一件代发详情 impl
 *
 * @author sunlaiqian
 * @date 2020-12-02 18:31:31
 */
@Service
public class UndertakesDetailServiceImpl extends ServiceImpl<UndertakesDetailMapper, UndertakesDetail> implements UndertakesDetailService {

    @Autowired
    private UndertakesDetailService undertakesDetailService;

    @Override
    public ResultUtil UndertakesDetaillist(Integer page, Integer limit, String conditions){
        QueryWrapper<UndertakesDetail> wrapper = new QueryWrapper<>();
        Map<String, String> map = UrlToMap.paramToMap(conditions);
        for(Map.Entry<String, String> entry : map.entrySet()){
            wrapper.like(entry.getKey(), entry.getValue());
        }
        wrapper.eq("delete_flag", DeleteFlagEnum.NOT_DELETE.getCode());
        return new ResultUtil(ResultMapInfo.GETSUCCESS,undertakesDetailService.page(new Page<>(page,limit),wrapper));
    }

    @Override
    public ResultUtil addUndertakesDetail(UndertakesDetail undertakesDetail) {
        boolean save = undertakesDetailService.save(undertakesDetail);
        return new ResultUtil(save ? ResultMapInfo.ADDSUCCESS:ResultMapInfo.ADDFAIL);
    }

    @Override
    public ResultUtil getUndertakesDetailById(Long id) {
        UndertakesDetail undertakesDetail = undertakesDetailService.getById(id);
        return undertakesDetail == null ?  new ResultUtil(ResultMapInfo.GETFAIL) : new ResultUtil(ResultMapInfo.GETSUCCESS,undertakesDetail);
    }

    @Override
    public ResultUtil delUndertakesDetailById(Long id) {
        UndertakesDetail undertakesDetail = new UndertakesDetail();
        undertakesDetail.setId(id);
        undertakesDetail.setDeleteFlag(DeleteFlagEnum.DELETE.getCode());
        boolean delState = undertakesDetailService.updateById(undertakesDetail);
        return delState ?  new ResultUtil(ResultMapInfo.DELETESUCCESS) : new ResultUtil(ResultMapInfo.DELETEFAIL);
    }

    @Override
    public ResultUtil editUndertakesDetail(UndertakesDetail undertakesDetail) {
        boolean editState = undertakesDetailService.updateById(undertakesDetail);
        return editState ?  new ResultUtil(ResultMapInfo.EDITSUCCESS) : new ResultUtil(ResultMapInfo.EDITFAIL);
    }

}
